#include "ledcontrolnode.h"
#include "ui_ledcontrolnode.h"

LedControlNode::LedControlNode(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LedControlNode)
{
    ui->setupUi(this);
    msocket = new QTcpSocket;
    //链接服务器
    msocket->connectToHost("192.168.192.1",5678);
}

LedControlNode::~LedControlNode()
{
    delete ui;
    delete msocket;
}

void LedControlNode::on_led1_clicked(bool checked)
{
    if(checked)
    {
        led1Status = "open";
        QString data=QString("{led1:%1,led2:%2}").arg("open").arg(led2Status);
        msocket->write(data.toUtf8());
    }else {
        led1Status = "close";
        QString data=QString("{led1:%1,led2:%2}").arg("close").arg(led2Status);
        msocket->write(data.toUtf8());
    }
}

void LedControlNode::on_led2_clicked(bool checked)
{
    if(checked)
    {
        led2Status = "open";
        QString data=QString("{led1:%1,led2:%2}").arg(led1Status).arg("open");
        msocket->write(data.toUtf8());
    }else {
        led2Status = "close";
        QString data=QString("{led1:%1,led2:%2}").arg(led1Status).arg("close");
        msocket->write(data.toUtf8());
    }
}
